package com.yanqu.road.server.cmd.wingroom;

import com.yanqu.road.entity.wingroom.CrossWingRoomEventData;
import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.wingroom.CrossWingRoomMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ：zfr
 * @date ：2022/2/11 14:23
 */
@Cmd(code = CrossProtocol.C_WING_ROOM_GET_OTHER_PLAYER_EVENT_REWARD_RESP, desc = "领取其他玩家厢房事件的奖励返回")
public class GetOtherPlayerEventRewardRespCrossCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        WingRoomProto.GetOtherPlayerEventRewardRespCrossMsg respCrossMsg = WingRoomProto.GetOtherPlayerEventRewardRespCrossMsg.parseFrom(packet.getBytes());
        YanQuMessage message = YanQuMessageUtils.buildMessage(Protocol.S_WING_ROOM_GET_EVENT_REWARD_CROSS_RESP, respCrossMsg.getResp());
        //先更新缓存，不然不及时(整个字段后面会被区服同步消息覆盖)
        if(respCrossMsg.getResp().getRet() == 0){
            CrossWingRoomEventData eventData = CrossWingRoomMgr.getCrossWingRoomEventDataMap().get(respCrossMsg.getResp().getHostUserId());
            if(eventData != null){
                //synchronized (eventData){
                    //if(!eventData.getGetRewardUserList().contains(respCrossMsg.getOriPlayerId())){
                        //eventData.getGetRewardUserList().add(respCrossMsg.getOriPlayerId());
                    //}
                //}
            }
        }
        MessageHelper.sendPacket(respCrossMsg.getOriServerId(), respCrossMsg.getOriPlayerId(), message);
    }
}
